<?php


$ruta=$_SERVER['DOCUMENT_ROOT']."/viventura"."/MDTour";
include_once("$ruta/conf/CConfig.php");
include_once("$ruta/star.php");
include_once("$ruta/MDItinerary/ServicesByDay.php");


if (!isset($_POST['idOpe'])) {$_POST['idOpe'] = "NULL"; }
if (!isset($_POST['idGuide'])) {$_POST['idGuide'] = "NULL"; }
if (!isset($_POST['idRest'])) {$_POST['idRest'] = "NULL"; }
if (!isset($_POST['idTrans'])) {$_POST['idTrans'] = "NULL"; }

if (!isset($_POST['idPackTour'])) {$_POST['idPackTour'] = "NULL"; }
if (!isset($_POST['forday'])) {$_POST['forday'] = "NULL"; }
$DayAct=$_POST['forday'];
$idPackTour=$_POST['idPackTour'];

$idOpe = $_POST['idOpe'];
$idGuide = $_POST['idGuide'];
$idRest = $_POST['idRest'];
$idTrans = $_POST['idTrans'];


//echo $idPackTour;
    if($idGuide!="NULL"){
         $source = "select `guidetc_idGuide` ,`DesSer` ,`DayActTra` ,`DateActTra` ,`CanIteRec` ,`PriUni` ,`CommSer` from pack_has_tour_has_guidetc where idPackTourGui = $idGuide";
        $ans = CModelo::getInstance()->getData($source);
        foreach ($ans as $r => $k){ $ans2 = $k; foreach ($ans2 as $r1 => $k1 ){ $servicio[] = $k1;}}
        
        $DateActTra = "NULL";
        $qu = "INSERT INTO  `pack_has_tour_has_guidetc` (`idPackTourGui` ,`guidetc_idGuide` ,`DesSer` ,`DayActTra` ,`DateActTra` ,`CanIteRec` ,`PriUni` ,`CommSer`, `pack_has_tour_idPackTour`)
        VALUES (NULL , '$servicio[0]', '$servicio[1]', '$DayAct', $DateActTra , '$servicio[4]', '$servicio[5]',  '$servicio[6]', '$idPackTour')";
        //echo $qu;
        $insertado = CModelo::getInstance()->insertData($qu);
       }
    
    
    if($idOpe!="NULL"){        
        foreach($idOpe as $r => $c){
            
              $source = "select `operador_idOpe` ,`DesSer` ,`DayActTra` ,`DateActTra` ,`CanIteRec` ,`PriUni` ,`CommSer`,`actividades_idAct` from actividades_has_tour_has_pasajero where idActPaxTour = $c";
              $ans = CModelo::getInstance()->getData($source);
              
              foreach ($ans as $r => $k){ $ans2 = $k; foreach ($ans2 as $r1 => $k1 ){ $servicio[] = $k1;}}
              
              $DateActTra = "NULL";
              $qu = "INSERT INTO  `actividades_has_tour_has_pasajero` (`idActPaxTour` ,`operador_idOpe` ,`DesSer` ,`DayActTra` ,`DateActTra` ,`CanIteRec` ,`PriUni` ,`CommSer`, `actividades_idAct`, `pack_has_tour_idPackTour`)
                    VALUES (NULL , '$servicio[0]', '$servicio[1]', '$DayAct', $DateActTra , '$servicio[4]', '$servicio[5]',  '$servicio[6]', '$servicio[7]', '$idPackTour')";
              echo $qu;      
       
              $idt = CModelo::getInstance()->insertData($qu);
              echo $idt;
            }
    }
    
    if($idRest!="NULL"){
        
        $source = "select `restaurant_idRest` ,`DesSer` ,`DayActRes` ,`DateActRes` ,`CanIteRec` ,`PriUni` ,`CommSer` from restaurant_has_pack_has_tour where ResPackTour = $idRest";
        //echo $source;
        $ans = CModelo::getInstance()->getData($source);
        foreach ($ans as $r => $k){ $ans2 = $k; foreach ($ans2 as $r1 => $k1 ){ $servicio[] = $k1;}}
        
        
        $DateActRes = "NULL";
        $qu = "INSERT INTO  `restaurant_has_pack_has_tour` (`ResPackTour` ,`restaurant_idRest` ,`DesSer` ,`DayActRes` ,`DateActRes` ,`CanIteRec` ,`PriUni` ,`CommSer`, `pack_has_tour_idPackTour`)
        VALUES (NULL , '$servicio[0]', '$servicio[1]', '$DayAct', $DateActRes , '$servicio[4]', '$servicio[5]',  '$servicio[6]', '$idPackTour')";
        $insertado = CModelo::getInstance()->insertData($qu);
        //echo $insertado;
        
     }

    if($idTrans!="NULL"){
        
        $source = "select `transporte_idTrans` ,`DesSer` ,`DayActTra` ,`DateActTra` ,`CanIteRec` ,`PriUni` ,`CommSer` from transporte_has_pack_has_tour where TranPackTour = $idTrans";
        //echo $source;
        $ans = CModelo::getInstance()->getData($source);
        foreach ($ans as $r => $k){ $ans2 = $k; foreach ($ans2 as $r1 => $k1 ){ $servicio[] = $k1;}}
        
        $DateActTra = "NULL";
        $qu = "INSERT INTO  `transporte_has_pack_has_tour` (`TranPackTour` ,`transporte_idTrans` ,`DesSer` ,`DayActTra` ,`DateActTra` ,`CanIteRec` ,`PriUni` ,`CommSer`, `pack_has_tour_idPackTour`)
        VALUES (NULL , '$servicio[0]', '$servicio[1]', '$DayAct', $DateActTra , '$servicio[4]', '$servicio[5]',  '$servicio[6]', '$idPackTour')";
        //echo $qu;
        $insertado = CModelo::getInstance()->insertData($qu);
        //echo $insertado;

         
    }
        $DayAct1 = "=".$DayAct;
        ServicesByDay::getInstance()->DrawTable("Resumen día $DayAct (transporte)",$idPackTour,$DayAct1,"transporte_has_pack_has_tour","DayActTra","1");
        ServicesByDay::getInstance()->DrawTable("Resumen día $DayAct (alimentación)",$idPackTour,$DayAct1,"restaurant_has_pack_has_tour","DayActRes","2");
        ServicesByDay::getInstance()->DrawTable("Resumen día $DayAct (guiado)",$idPackTour,$DayAct1,"pack_has_tour_has_guidetc","DayActTra","3");
        ServicesByDay::getInstance()->DrawTable("Resumen día $DayAct (operadores)",$idPackTour,$DayAct1,"actividades_has_tour_has_pasajero","DayActTra","4");
  
      
//echo "eco!!!!!!!!!!!!!!!!!!!!!";

?>

